<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>极化码 Fast-SCL 仿真平台</title>
    
    <!-- 国内CDN资源 -->
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/daisyui/4.12.10/full.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/Chart.js/4.4.1/chart.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.6.7/axios.min.js"></script>
    
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .glass-card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
    </style>
</head>
<body class="min-h-screen gradient-bg">
    <div class="container mx-auto px-4 py-8">
        <!-- 标题 -->
        <div class="text-center mb-8">
            <h1 class="text-4xl font-bold text-white mb-2">
                <i class="fas fa-broadcast-tower mr-3"></i>
                极化码 Fast-SCL 仿真平台
            </h1>
            <p class="text-white/80 text-lg">Polar Code Fast Successive Cancellation List Decoding</p>
        </div>

        <!-- 主界面 -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            <!-- 参数配置面板 -->
            <div class="lg:col-span-1">
                <div class="glass-card rounded-xl p-6">
                    <h2 class="text-xl font-semibold text-white mb-4">
                        <i class="fas fa-cogs mr-2"></i>参数配置
                    </h2>
                    
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-white/90 mb-2">码长 N</label>
                            <select id="codeLength" class="w-full px-3 py-2 bg-white/20 border border-white/30 rounded-lg text-white placeholder-white/70">
                                <option value="256">256</option>
                                <option value="512">512</option>
                                <option value="1024" selected>1024</option>
                                <option value="2048">2048</option>
                                <option value="4096">4096</option>
                            </select>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-white/90 mb-2">码率 R</label>
                            <input type="range" id="codeRate" min="0.1" max="0.9" step="0.1" value="0.5" 
                                   class="w-full h-2 bg-white/20 rounded-lg appearance-none cursor-pointer">
                            <div class="text-center text-white/80 mt-1">
                                <span id="codeRateValue">0.5</span>
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-white/90 mb-2">列表大小 L</label>
                            <select id="listSize" class="w-full px-3 py-2 bg-white/20 border border-white/30 rounded-lg text-white">
                                <option value="2">2</option>
                                <option value="4">4</option>
                                <option value="8" selected>8</option>
                                <option value="16">16</option>
                                <option value="32">32</option>
                            </select>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-white/90 mb-2">SNR范围 (dB)</label>
                            <div class="grid grid-cols-3 gap-2">
                                <input type="number" id="snrStart" value="0" step="0.5" 
                                       class="px-2 py-1 bg-white/20 border border-white/30 rounded text-white text-sm" 
                                       placeholder="起始">
                                <input type="number" id="snrEnd" value="4" step="0.5" 
                                       class="px-2 py-1 bg-white/20 border border-white/30 rounded text-white text-sm" 
                                       placeholder="结束">
                                <input type="number" id="snrStep" value="0.5" step="0.1" 
                                       class="px-2 py-1 bg-white/20 border border-white/30 rounded text-white text-sm" 
                                       placeholder="步长">
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-white/90 mb-2">仿真次数</label>
                            <input type="number" id="numTrials" value="100" min="10" max="10000" 
                                   class="w-full px-3 py-2 bg-white/20 border border-white/30 rounded-lg text-white">
                        </div>
                    </div>
                    
                    <div class="mt-6 space-y-2">
                        <button id="startBtn" class="w-full bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-lg transition duration-200">
                            <i class="fas fa-play mr-2"></i>开始仿真
                        </button>
                        
                        <button id="stopBtn" class="w-full bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded-lg transition duration-200" disabled>
                            <i class="fas fa-stop mr-2"></i>停止仿真
                        </button>
                    </div>
                    
                    <!-- 进度条 -->
                    <div class="mt-4">
                        <div class="flex justify-between text-sm text-white/80 mb-1">
                            <span>进度</span>
                            <span id="progressText">0%</span>
                        </div>
                        <div class="w-full bg-white/20 rounded-full h-2">
                            <div id="progressBar" class="bg-green-500 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
                
                <!-- 统计信息 -->
                <div class="glass-card rounded-xl p-6 mt-4">
                    <h3 class="text-lg font-semibold text-white mb-3">
                        <i class="fas fa-chart-bar mr-2"></i>统计信息
                    </h3>
                    <div class="space-y-2 text-sm text-white/80">
                        <div class="flex justify-between">
                            <span>码长:</span>
                            <span id="statN">1024</span>
                        </div>
                        <div class="flex justify-between">
                            <span>信息位:</span>
                            <span id="statK">512</span>
                        </div>
                        <div class="flex justify-between">
                            <span>码率:</span>
                            <span id="statR">0.5</span>
                        </div>
                        <div class="flex justify-between">
                            <span>列表大小:</span>
                            <span id="statL">8</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 结果显示区域 -->
            <div class="lg:col-span-2">
                <div class="glass-card rounded-xl p-6">
                    <h2 class="text-xl font-semibold text-white mb-4">
                        <i class="fas fa-chart-line mr-2"></i>仿真结果
                    </h2>
                    
                    <!-- 图表容器 -->
                    <div class="bg-white/10 rounded-lg p-4">
                        <canvas id="berChart" width="400" height="200"></canvas>
                    </div>
                    
                    <!-- 结果表格 -->
                    <div class="mt-4 overflow-x-auto">
                        <table class="w-full text-sm text-white/80">
                            <thead>
                                <tr class="border-b border-white/20">
                                    <th class="text-left py-2">SNR (dB)</th>
                                    <th class="text-left py-2">BER</th>
                                </tr>
                            </thead>
                            <tbody id="resultsTable">
                                <tr>
                                    <td colspan="2" class="text-center py-4 text-white/60">
                                        等待仿真结果...
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                
                <!-- 算法说明 -->
                <div class="glass-card rounded-xl p-6 mt-4">
                    <h3 class="text-lg font-semibold text-white mb-3">
                        <i class="fas fa-info-circle mr-2"></i>算法说明
                    </h3>
                    <div class="text-sm text-white/80 space-y-2">
                        <p><strong>Fast-SCL译码:</strong> 在SCL译码基础上加入早期终止和路径修剪优化，显著降低复杂度。</p>
                        <p><strong>极化码:</strong> 通过信道极化构造，将N个独立信道转化为N个可靠性不同的极化信道。</p>
                        <p><strong>BER:</strong> 比特误码率，衡量译码性能的重要指标。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
</body>
</html>
